/*
 * CollectShopListItem.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Shop;
import com.yidiandao.business.data.event.CollectShopEvent;
import com.yidiandao.business.ui.collect.CollectActivity;
import com.yidiandao.business.ui.shopdetail.ShopDetailActivity;
import com.yidiandao.business.ui.widget.dialog.BusinessDialog;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.CollectShopHolder;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.UIUtils;
import com.yidiandao.business.utils.UmengUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * 收藏 - 商店 - ListItem
 */
public class CollectShopListItem extends DisplayListItem<CollectShopHolder, Shop> {

    public CollectShopListItem(Shop s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, CollectShopHolder holder) {

        //logo
        ImageLoader.loadImage(context, holder.mIvShopInfoImage, data.getShopLogo());
        //商店名
        holder.mTvShopName.setText(data.getSupplierName());
        //描述
        holder.mTvShopDetail.setText(
                UIUtils.getString(
                        R.string.shop_sales_count, data.getGoodsNumber()));
        //进店
        holder.mTvGoToShop.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        UmengUtils.onEvent(context, R.string.umeng_collect_enter_shop);
                        ShopDetailActivity.actionStart((Activity) context, data.getSupplierId());
                    }
                });
        //取消收藏
        holder.mTvCollect.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        UmengUtils.onEvent(context, R.string.umeng_collect_cancle);
                        CollectActivity activity = (CollectActivity) context;
                        new BusinessDialog.Builder(activity)
                                .setTitle(R.string.dialog_collectTip)
                                .setPositiveButton(
                                        R.string.dialog_sure,
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                EventBus.getDefault()
                                                        .post(
                                                                new CollectShopEvent(
                                                                        data.getSupplierId(),
                                                                        CollectShopListItem.this));
                                            }
                                        })
                                .setNegativeButton(R.string.dialog_cancel, null)
                                .create()
                                .show();
                    }
                });
        //查看信息
        holder.mLlytShopInfo.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        UmengUtils.onEvent(context, R.string.umeng_collect_detail);
                        ShopDetailActivity.actionStart((Activity) context, data.getSupplierId());
                    }
                });
    }

    @Override
    public String getDisplayItemTag() {
        return CollectShopListItem.class.getSimpleName();
    }

    @Override
    public Class<CollectShopHolder> getViewHolderClazz() {
        return CollectShopHolder.class;
    }
}
